<script setup>
import QuestionItem from "../components/Question/QuestionItem.vue"
</script>

<template>
    <div class="common-layout">
        <!-- 标题 -->
        <el-header class="element-center">
            <h1>{{ title }}</h1>
        </el-header>

        <el-container>
            <!-- 侧边空白 -->
            <el-aside width="10%"></el-aside>
            <el-container style="border:  2px solid gray">
                <el-main>
                    <el-row :span="24" v-for="(item, index) in information.data" :key="index">
                        <!-- 赋予数据并循环该项 -->
                        <QuestionItem :information="item">
                        </QuestionItem>
                    </el-row>
                </el-main>
            </el-container>
            <el-aside width="10%"></el-aside>
        </el-container>
    </div>


</template>

<script>
export default {
    setup() {

    },
    data() {
        return {
            title: '最新问卷调查',
            information: {
                "status": true,
                "message": "查询成功",
                "data": [
                    {
                        "id": 1,
                        "title": "error",
                        "description": "error",
                        "created_at": "error",
                        "updated_at": "error"
                    },
                    {
                        "id": 2,
                        "title": "error",
                        "description": "error",
                        "created_at": "error",
                        "updated_at": "error"
                    }
                ]
            }

        }

    }, created() {
        this.getAllSurvey();

    },
    methods: {
        getAllSurvey() {
            this.$axios.get('/index.php/index/getAllSurvey')
                .then(response => {
                    console.log("userwaitdata的请求状态：" + response.data.message);
                    console.log("userwaitdata请求到的数据：");
                    console.log(response.data);
                    this.information = response.data;
                })
                .catch(error => {
                    console.error('Error fetching data:', error);
                    this.message = 'Error: ' + error.message;
                });
        },
        goToNewQuestionnaire() {

        },
    }

}
</script>

<style>
.element-center {
  display: flex;
  justify-content: center;
}
</style>